package com.lmn.bus.rocketmq;

import com.lmn.bus.rocketmq.endpoint.MyBusEndpoint;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.bus.BusAutoConfiguration;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.cloud.bus.ServiceMatcher;
import org.springframework.cloud.stream.config.BindingServiceProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyBusAutoConfiguration extends BusAutoConfiguration {

    public MyBusAutoConfiguration(ServiceMatcher serviceMatcher, BindingServiceProperties bindings, BusProperties bus) {
        super(serviceMatcher, bindings, bus);
    }

    @Configuration
    protected static class BusConfiguration {
        protected BusConfiguration() {
        }

        @Configuration
        @ConditionalOnClass({Endpoint.class})
        protected static class GuavaBusEndpointConfiguration {
            protected GuavaBusEndpointConfiguration() {
            }

            @Bean
            public MyBusEndpoint environmentBusEndpoint(ApplicationContext context) {
                return new MyBusEndpoint(context, context.getId());
            }
        }
    }

}
